<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="考勤管理">
			<view slot="right" @click="search"><u-icon name="search" size="20" color="#162233"></u-icon></view>
		</u-navbar>
		<d-select :options="options" @query="setParams"></d-select>

		<view class="d-p-30">
			<view class="card d-p-30">
				<view class="d-font-32" style="font-weight: bold;color: #323334;">考勤概览</view>
				<view class="d-flex d-m-t-20 d-font-24 d-text-center" style="color: #4E5C70;">
					<view class="d-flex-1">
						<view>实名总人数</view>
						<view class="d-m-t-10" style="color: #21A5F3;font-weight: bold;font-size: 42rpx;">{{ count ? count.staffs : 0 }}</view>
					</view>
					<view class="d-flex-1">
						<view>进场总人数</view>
						<view class="d-m-t-10" style="color: #21A5F3;font-weight: bold;font-size: 42rpx;">{{ count ? count.istaffs : 0 }}</view>
					</view>
					<view class="d-flex-1">
						<view>今日考勤数</view>
						<view class="d-m-t-10" style="color: #21A5F3;font-weight: bold;font-size: 42rpx;">{{ count ? count.atdStaffs : 0 }}</view>
					</view>
					<view class="d-flex-1">
						<view>今日考勤率</view>
						<view class="d-m-t-10" style="color: #21A5F3;font-weight: bold;font-size: 42rpx;">{{ count ? count.atdRate : 0 }}</view>
					</view>
				</view>
			</view>
			<view class="d-font-32 d-m-t-40" style="font-weight: bold;color: #323334;">考勤列表</view>
			<template v-if="list && list.length > 0">
				<view class="card d-p-30 d-m-t-30" v-for="(item, index) in list" :key="index" @click="workGroup(item)">
					<view class="d-flex">
						<view class="d-font-28 d-flex-1" style="color: #151C24;font-weight: bold;">{{ item.gcmc }}</view>
					<!-- 	<view class="d-font-24 d-flex" style="color: #ADB4BD;">
							<view style="position: relative;top: -2rpx;">详情</view>
							<u-icon name="arrow-right" color="#ADB4BD" size="24rpx"></u-icon>
						</view> -->
					</view>
					<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
						<view class="d-flex-1">
							<text>属地类型</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.districtName }}</text>
						</view>
						<view style="width: 260rpx;">
							<text>今日考勤数</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.atdStaff }}</text>
						</view>
					</view>
					<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
						<view class="d-flex-1">
							<text>实名总人数</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.staffs }}</text>
						</view>
						<view style="width: 260rpx;">
							<text>今日考勤率</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.atdRate }}</text>
						</view>
					</view>
					<view class="d-flex d-m-t-20 d-font-24" style="color: #5D6672;">
						<view class="d-flex-1">
							<text>进场总人数</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.staffs }}</text>
						</view>
						<view style="width: 260rpx;">
							<text>考勤来源</text>
							<text class="d-m-l-20" style="color: #162233;">{{ item.sjly }}</text>
						</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view style="padding: 10vh 0;"><u-empty text="暂无数据" icon="/static/image/none.png"></u-empty></view>
			</template>
		</view>
	</view>
</template>

<script>
import { dictList, appNation, staffsStatistics, regionAtd } from '../../../common/api.js';
export default {
	data() {
		return {
			options: [
				{
					label: '属地',
					name: 'districtId',
					children: []
				},
				{
					label: '行业主管部门',
					name: 'xmtype',
					children: []
				}
			],
			queryParams: {},
			count: null,
			pageNum: 1,
			pageSize: 20,
			pageLast: 1,
			list: []
		};
	},
	onLoad() {
		this.init();
	},
	onReachBottom() {
		if (this.pageNum < this.pageLast) {
			++this.pageNum;
			this.getData().then(e => {
				this.list = this.list.concat(e.data);
				uni.hideLoading();
			});
		}
	},
	methods: {
		init() {
			let district, xmtype;
			// 属地
			appNation()
				.then(e => {
					district = e.data.map(e => {
						return {
							id: e.districtId,
							label: e.districtName
						};
					});
				})
				.then(() => {
					// 项目类型
					return dictList({
						type: 'xmtype'
					}).then(e => {
						xmtype = e.data.map(e => {
							return {
								id: e.dictValue,
								label: e.dictLabel
							};
						});
					});
				})
				.then(() => {
					this.options = [
						{
							label: '属地',
							name: 'districtId',
							children: district
						},
						{
							label: '行业主管部门',
							name: 'xmtype',
							children: xmtype
						}
					];
				})
				.then(() => {
					this.getInfo();
				});
		},
		getInfo() {
			staffsStatistics({
				params: {
					deptId: this.$user.deptId,
					...this.queryParams
				}
			}).then(e => {
				this.count = e.data;
			});
			this.pageNum = 1;
			this.getList().then(e => {
				this.list = e.data;
				this.pageLast = Math.ceil(e.total / this.pageSize);
				uni.hideLoading();
			});
		},
		getList() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			return regionAtd({
				params: {
					deptId: this.$user.deptId,
					...this.queryParams,
					pageSize: this.pageSize,
					pageNum: this.pageNum
				}
			});
		},
		setParams(e) {
			this.queryParams = e;
			this.getInfo();
		},
		search() {
			uni.$u.route({
				url: '/pages/index/work/search'
			});
		},
		workGroup(item) {
			uni.$u.route({
				url: '/pages/index/work/workGroup',
				params: {
					gcbh: item.id,
				}
			});
		}
	}
};
</script>

<style lang="scss">
.card {
	box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
	border-radius: 10rpx;
	background-color: #ffffff;
}
page {
	background-color: #fbfcfc;
}
</style>
